package cn.innosmart.aq.bean;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by David on 2015/7/7.
 */
public class BoxBean implements Parcelable {
    public static final Parcelable.Creator<BoxBean> CREATOR = new Parcelable.Creator<BoxBean>() {
        public BoxBean createFromParcel(Parcel source) {
            return new BoxBean(source);
        }

        public BoxBean[] newArray(int size) {
            return new BoxBean[size];
        }
    };
    private String uid;
    private String username;
    private String password;
    private String title;
    private String hubId;
    private String owner;
    //指派信息
    private ArrayList<String> assingTo;
    //是否同步过的标志
    private boolean isSynced;

    public BoxBean() {
    }

    public BoxBean(String uid, String username, String password, String title) {
        this.uid = uid;

        this.username = username;
        this.password = password;
        this.title = title;
    }


    protected BoxBean(Parcel in) {
        this.uid = in.readString();
        this.username = in.readString();
        this.password = in.readString();
        this.title = in.readString();
        this.hubId = in.readString();
        this.owner = in.readString();
        this.assingTo = in.createStringArrayList();
        this.isSynced = in.readByte() != 0;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getHubId() {

        return hubId;
    }

    public void setHubId(String hubId) {
        this.hubId = hubId;
    }

    public ArrayList<String> getAssingTo() {
        return assingTo;
    }

    public void setAssingTo(ArrayList<String> assingTo) {
        this.assingTo = assingTo;
    }

    public boolean isSynced() {
        return isSynced;
    }

    public void setIsSynced(boolean isSynced) {
        this.isSynced = isSynced;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "BoxBean{" +
                "uid='" + uid + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", title='" + title + '\'' +
                '}';
    }

    public JSONObject getModifyInfo() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("id", hubId);
            jsonObject.put("username", username);
            jsonObject.put("password", password);
            jsonObject.put("alias", title);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.uid);
        dest.writeString(this.username);
        dest.writeString(this.password);
        dest.writeString(this.title);
        dest.writeString(this.hubId);
        dest.writeString(this.owner);
        dest.writeStringList(this.assingTo);
        dest.writeByte(isSynced ? (byte) 1 : (byte) 0);
    }
}
